import toBeSure from '../request-functions/toBeSure';

import {
    toast
} from 'nc-lightapp-front';


const batchAddSubTemplate = 'batchAddSub';
const batchAddSubTaleTemplate = 'batchAddSubTaleTemplate';

export default function(language) {
    const {
        editTable: {
            getAllData,
            checkRequired
        },
        func_type,
        param_str,
        pk_org
    } = this.props;

    const {
        currentForm
    } = this.state;

    let allTableData = getAllData(batchAddSubTaleTemplate);

    if(checkRequired(batchAddSubTaleTemplate, allTableData.rows)) {
        let postData = {
            func_type: func_type,
            model: {
                ...allTableData,
                areacode: currentForm
            },
            table_code: currentForm,
            param_str: param_str,
            pk_org: pk_org
        };
    
        toBeSure(postData)
            .then((res) => {
                if(res.success) {
                    this.closeModal();
                    toast({
                        color: 'success',
                        content: language['hi6007-000004']/* 国际化处理： 批量增加子集成功!*/
                    });
                }
            })
    }
}
